package com.yigang.controller;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yigang.entity.Classification;
import com.yigang.service.ClassificationService;
import com.yigang.utils.ResultUtil;
/**
 * @author 陈佳祥
 *商品分类管理
 */
@Controller
@RequestMapping("/classification")
public class ClassificationController {

	@Autowired
	private ClassificationService classificationService;
	//椤甸潰閲嶅畾鍚�
	@RequestMapping("classificationList")
	public String classificationList() {
		return "jsp/classification/classificationList";
	}
	@RequestMapping("addClassification")
	public String addClassification() {
		return "jsp/classification/addClassification";
	}
	
	@RequestMapping("editClassification/{classification_id}")
	public String editClassification(@PathVariable("classification_id") int classification_id, HttpSession session) {
		Classification classification = classificationService.selectClassificationById(classification_id);
	
		session.setAttribute("classification", classification);
		return "jsp/classification/editClassification";
	}
	
	//澧炲垹鏌ユ敼鏂规硶
	@RequestMapping("insertClassification")
	@ResponseBody
	public ResultUtil insertClassification(Classification record) {
		 classificationService.insertSelective(record);
		return ResultUtil.ok();

	}

	@RequestMapping("deleteClassificationById")
	@ResponseBody
	public ResultUtil deleteClassificationById(int classification_id) {
		
		return classificationService.deleteByPrimaryKey(classification_id);
	}

	@RequestMapping("getClassificationList")
	@ResponseBody
	public ResultUtil getClassificationList(Integer page, Integer limit, Classification record) {

		return classificationService.selectClassificationList(page, limit, record);
	}

	@RequestMapping("updateClassification")
	@ResponseBody
	public ResultUtil updateClassification(Classification record) throws ParseException {
		
		return classificationService.updateByPrimaryKeySelective(record);
	}
	@RequestMapping("updateClassificationStatusById")
	@ResponseBody
	public ResultUtil updateProductStatusById(int classification_id, int classification_display) {
		return classificationService.updateClassificationStatusById(classification_id, classification_display);
	}


}
